//
//  ViewController.m
//  Animation
//
//  Created by iD Student on 6/26/13.
//  Copyright (c) 2013 iD Student. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view, typically from a nib.
    animatedImage.animationImages = [NSArray arrayWithObjects: [UIImage imageNamed:@"IMG1.png"],
                                     [UIImage imageNamed:@"IMG2.png"],
                                     [UIImage imageNamed:@"IMG3.png"],
                                     [UIImage imageNamed:@"IMG4.png"],
                                     [UIImage imageNamed:@"IMG5.png"],
                                     [UIImage imageNamed:@"IMG6.png"],
                                     [UIImage imageNamed:@"IMG7.png"],
                                     [UIImage imageNamed:@"IMG8.png"],
                                     [UIImage imageNamed:@"IMG9.png"],
                                     [UIImage imageNamed:@"IMG10.png"],
                                     [UIImage imageNamed:@"IMG11.png"],
                                     [UIImage imageNamed:@"IMG12.png"], nil];
    animatedImage.animationDuration = 1.0;
    NSURL *url = [[NSBundle mainBundle] URLForResource:@"Slug_Clip" withExtension:@"mp3"];
    NSError *error;
    slugSound = [[AVAudioPlayer alloc] initWithContentsOfURL: url error: &error];
  
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
-(IBAction)start :(id)sender;
{
   
    [animatedImage startAnimating];
    NSLog(@"Start animation");
    
    timer = [NSTimer scheduledTimerWithTimeInterval:.5 target:self selector:@selector(playSound) userInfo:nil repeats:YES];
    
}
-(IBAction)stop :(id)sender;
{
    [animatedImage stopAnimating];
    NSLog(@"Stop animation");
  
    [timer invalidate];
}
- (void) playSound
{
    [slugSound play];
}
@end
